package applications.libraryForm.ui.lib;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;

import org.objectweb.fractal.fraclet.annotations.Component;
import org.objectweb.fractal.fraclet.annotations.Interface;
import org.objectweb.fractal.fraclet.annotations.Requires;

@Component(provides = {@Interface(name = "jButtonItf", signature = org.objectweb.fractal.swing.JButtonItf.class), @Interface(name = "jButtonAttributes", signature = org.objectweb.fractal.swing.JButtonAttributes.class), @Interface(name = "uicontainerservice", signature = ontocompo.api.UIContainerService.class), @Interface(name = "ontocompointrospection", signature = ontocompo.api.OntoCompoIntrospection.class)})

public class ValidateStudentNameButton extends JButton  implements org.objectweb.fractal.swing.JButtonItf, org.objectweb.fractal.swing.JButtonAttributes, ontocompo.api.UIContainerService, ontocompo.api.OntoCompoIntrospection {


	private String uid;
	private org.objectweb.fractal.api.Component c;

	@Requires(name = "jTextFieldItf")
	private org.objectweb.fractal.swing.JTextFieldItf jTextFieldItf;

	@Requires(name = "libraryformdirectoryservice")
	private applications.libraryForm.fc.api.LibraryFormDirectoryService libraryformdirectoryservice;




	public ValidateStudentNameButton() {
		super();
		this.uid = "applications.libraryForm.ui.lib.ValidateStudentNameButton";
		System.out.println(this.toString() + "   created!");

	}


	@Override
	public void init() {
		// TODO Auto-generated method stub

		this.setText("Search");
		this.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				showStudentInformations();

			}
		});

	}

	protected void showStudentInformations() {
		// TODO Auto-generated method stub

		if (this.jTextFieldItf.getText().equals("12345"))
		{
			this.libraryformdirectoryservice.setStudentNumber(this.jTextFieldItf.getText());


		}
		else

			if (this.jTextFieldItf.getText().equals("56789"))
			{
				this.libraryformdirectoryservice.setStudentNumber(this.jTextFieldItf.getText());


			}

			else
			{
				JOptionPane.showMessageDialog(null,
						" this student id : "+this.jTextFieldItf.getText()+ "  doesn't exist !!","Error",
						JOptionPane.ERROR_MESSAGE);
			}
		

		
	}





	@Override
	public JComponent getComponentItSelf() {
		// TODO Auto-generated method stub
		return this;
	}

	@Override
	public void update(Object arg0) {
		// TODO Auto-generated method stub

	}

	public String toString() {
		return "ValidateStudentNameButton";
	}


	@Override
	public org.objectweb.fractal.api.Component getFractalComponent() {
		// TODO Auto-generated method stub
		return this.c;
	}

	@Override
	public String getUid() {
		// TODO Auto-generated method stub
		return this.uid;
	}

	@Override
	public void setFractalComponent(org.objectweb.fractal.api.Component c) {
		// TODO Auto-generated method stub
		this.c = c;

	}

	@Override
	public void setUid(String uid) {
		// TODO Auto-generated method stub
		this.uid= uid;

	}



}

